package com.kangye.learnteacher.controller;

import com.github.pagehelper.PageHelper;
import com.kangye.learnteacher.entity.QuestionBank;
import com.kangye.learnteacher.entity.StudentPaper;
import com.kangye.learnteacher.entity.Subject;
import com.kangye.learnteacher.service.impl.PaperServiceImpl;
import com.kangye.learnteacher.util.RedisStorageUtil;
import com.kangye.learnteacher.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @program: learndeduo
 * @description: 试卷控制层
 * @author: 冯钧豪
 * @create: 2021-05-17 19:58
 **/
@RestController
@CrossOrigin
public class PaperController {
    @Autowired
    private PaperServiceImpl paperService; //注入service层
    @Autowired
    private RedisStorageUtil redisStorageUtil; //注入redis工具类
    @RequestMapping(value = "/selPaper")
     /**
     *  模糊查询和搜索
     * 参宿spId,classesName 是模糊查询的条件
     * page,limit作为分页参宿
     * PageHelper.startPage(page, limit) 调用依赖工具传入分页
     * paperService.selPaper(spId,classesName); 调用paperService的selPaper查询方法,传入模糊查询的参宿
     * */
    public ViewJsonObject<StudentPaper> selPaper(Integer spId, String classesName,Integer page, Integer limit) {
        System.out.println(spId);
        PageHelper.startPage(page, limit);
        return paperService.selPaper(spId,classesName);
    }

    /**
     *  删除功能
     * @param spId 主键id
     * @return paperService.delPaper(spId) ,调用Service层的删除方法,传入主键id
     *
     *
     */
    @RequestMapping(value = "/delPaper")
    public Integer delPaper(Integer spId) {
        System.out.println("进来了删除的接口");
        return paperService.delPaper(spId);
    }

    @RequestMapping(value = "/updPaper")
    public List<Map<String, Object>> updPaper(Integer spId) {
        System.out.println("进来了修改接口");
        System.out.println(spId);
        List<Map<String, Object>> maps = paperService.updPaper(spId);
        return maps;
    }
    @RequestMapping(value = "/showAll")
    public ViewJsonObject showAll(){
        List<StudentPaper> list = (List<StudentPaper>) redisStorageUtil.getKeyOne("code");
        return new ViewJsonObject(list);
    }
      @RequestMapping(value = "/XkSelAll")
      public List XkSelAll(){
          return paperService.XkSelAll();
      }
    @RequestMapping(value = "/SelBank")
    public ViewJsonObject<StudentPaper> SelBank(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return paperService.SelBank();
    }
    @RequestMapping(value = "/AddPaper")
    public Integer AddPaper(StudentPaper studentPaper){
        Integer code = paperService.AddPaper(studentPaper);
        return code;
    }
    @RequestMapping(value = "/AddPaperUl")
    public QuestionBank AddPaperUl(Integer qbId){
        return paperService.AddPaperUl(qbId);
    }
}
